#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 05-Nov-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;

using Thn;
#endregion

namespace Thn.Interface.Vcl
{
    /// <summary>
    /// A custom flavor of <see cref="Thn.Interface.Vcl.Button"/> that supports convenient styling
    /// by using images.
    /// </summary>
    [ToolboxItem(true), DefaultProperty("Text"), DefaultEvent("Click"), ToolboxBitmap(typeof(ResourceBeacon), "Thn.Interface.Vcl.Resources.Icons.Button.bmp")]
#if DEBUG
    public
#else
    public
#endif
 class ImageButton : Button
    {
        #region Fields
        #endregion

        #region Properties

        #region Image Normal
        private Image mImageNormal = null;
        /// <summary>
        /// Gets/Sets ImageNormal
        /// </summary>
        [Browsable(true), DefaultValue(null), Category("Appearance"), Description("Image used when displaying normal state")]
        public Image ImageNormal
        {
            get { return mImageNormal; }
            set
            {
                mImageNormal = value;
                Invalidate();
            }
        }
        #endregion

        #region Image Over
        private Image mImageOver = null;
        /// <summary>
        /// Gets/Sets ImageOver
        /// </summary>
        [Browsable(true), DefaultValue(null), Category("Appearance"), Description("Image used when displaying Mouse Over state")]
        public Image ImageOver
        {
            get { return mImageOver; }
            set
            {
                mImageOver = value;
                Invalidate();
            }
        }
        #endregion

        #region Image Pressed
        private Image mImagePressed = null;
        /// <summary>
        /// Gets/Sets ImagePressed
        /// </summary>
        [Browsable(true), DefaultValue(null), Category("Appearance"), Description("Image used when displaying Pressed state")]
        public Image ImagePressed
        {
            get { return mImagePressed; }
            set
            {
                mImagePressed = value;
                Invalidate();
            }
        }
        #endregion

        #region Image Disabled
        private Image mImageDisabled = null;
        /// <summary>
        /// Gets/Sets ImageDisabled
        /// </summary>
        [Browsable(true), DefaultValue(null), Category("Appearance"), Description("Image used when displaying Disabled state")]
        public Image ImageDisabled
        {
            get { return mImageDisabled; }
            set
            {
                mImageDisabled = value;
                Invalidate();
            }
        }
        #endregion

        #region Text Offset X
        private int mTextOffsetX = 0;
        /// <summary>
        /// Gets/Sets the offset in x-axis for rendering text.
        /// </summary>
        [Browsable(true), DefaultValue(0), Category("Appearance"), Description("x-axis offset for rendering text")]
        public int TextOffsetX
        {
            get { return mTextOffsetX; }
            set
            {
                mTextOffsetX = value;
                mRecalculateLayout = true;
                Invalidate();
            }
        }
        #endregion

        #region Text Offset Y
        private int mTextOffsetY = 0;
        /// <summary>
        /// Gets/Sets the offset in y-axis for rendering text.
        /// </summary>
        [Browsable(true), DefaultValue(0), Category("Appearance"), Description("y-axis offset for rendering text")]
        public int TextOffsetY
        {
            get { return mTextOffsetY; }
            set
            {
                mTextOffsetY = value;
                mRecalculateLayout = true;
                mRenderRequired = true;
                Invalidate();
            }
        }
        #endregion

        #endregion

        #region On Calculate Layout
        /// <summary>
        /// Perform layout calculations neccessary for this control.
        /// </summary>
        protected override void OnCalculateLayout()
        {
            base.OnCalculateLayout();

            //offset text region
            Rectangle r = RenderContext.TextRegion;
            r = new Rectangle(r.Left + mTextOffsetX, r.Top + mTextOffsetY, r.Width, r.Height);
            RenderContext.TextRegion = r;
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public ImageButton()
        {
            //mTransparencyMethod = TransparencyMethod.ForcedPainting;
        }
        #endregion
    }
}
